package com.seal.pay.account.service.impl;

import com.seal.commons.copiers.BeanMapper;
import com.seal.pay.account.entity.AccountUnforzenRecord;
import com.seal.pay.account.bo.AccountUnforzenRecordBO;
import com.seal.pay.account.service.AccountUnforzenRecordService;
import com.seal.pay.account.repository.AccountUnforzenRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.time.LocalDateTime;
import java.util.Optional;


/**
* 功能描述: <br/>
* @date:    2020-11-23 21:25:01<br/>
* @author   yong.huang
* @since    JDK 1.8
*/
@Service
public class AccountUnforzenRecordServiceImpl implements AccountUnforzenRecordService {

    @Autowired
    private AccountUnforzenRecordRepository accountUnforzenRecordRepository;

    @Override
    public AccountUnforzenRecordBO create(AccountUnforzenRecordBO bo) {
        AccountUnforzenRecord entity = bo.toEntity(AccountUnforzenRecord.class);
        entity.setCreateDateTime(LocalDateTime.now());
        entity = accountUnforzenRecordRepository.saveAndFlush(entity);
        bo.parse(entity);
        return bo;
    }

    @Override
    public AccountUnforzenRecordBO getById(String id) {
        Optional<AccountUnforzenRecord> optional = accountUnforzenRecordRepository.findById(id);
        if(optional.isPresent()){
            return BeanMapper.cglibCopy(optional.get(), AccountUnforzenRecordBO.class);
        }
        return null;
    }


}